#ifndef __W25QXX_H__
#define __W25QXX_H__


#include "spi.h"
#include "gpio.h"

///////W25Q64ID////
#define W25Q64ID 0xef16
#define STORAGE_TOTAL_SIZE      32768*256// 总存储大小：8MB
#define STORAGE_BLK_SIZ         512  // 每块大小 512字节
#define STORAGE_BLK_NBR         (STORAGE_TOTAL_SIZE / STORAGE_BLK_SIZ)
#define STORAGE_LUN_NBR         1U  //最大逻辑单元数，
///////W25QXX CMD///////
#define ManufactDeviceID_CMD	0x90
#define READ_STATU_REGISTER_1   0x05
#define READ_STATU_REGISTER_2   0x35
#define READ_DATA_CMD	        0x03
#define WRITE_ENABLE_CMD	    0x06
#define WRITE_DISABLE_CMD	    0x04
#define SECTOR_ERASE_CMD	    0x20
#define CHIP_ERASE_CMD	        0xc7
#define KB32_ERASE_CMD	        0x52
#define KB64_ERASE_CMD	        0xd8
#define PAGE_PROGRAM_CMD        0x02

#define W25QXX_CS_L HAL_GPIO_WritePin(WQ_CS_GPIO_Port, WQ_CS_Pin, GPIO_PIN_RESET)
#define W25QXX_CS_H HAL_GPIO_WritePin(WQ_CS_GPIO_Port, WQ_CS_Pin, GPIO_PIN_SET)
uint16_t W25QXX_ReadID(void);
int W25QXX_Read(uint8_t* buffer, uint32_t start_addr, uint16_t nbytes);
void W25QXX_Write(uint8_t* buffer, uint32_t start_addr, uint16_t nbytes);
void W25QXX_Write_Enable(void);
void W25QXX_Write_Disable(void);
void W25QXX_Erase_Sector(uint32_t sector_addr);
void W25QXX_Page_Program(uint8_t* dat, uint32_t WriteAddr, uint16_t nbytes);
void W25QXX_Erase_Block(uint32_t block_addr, uint8_t mode);
void W25QXX_Erase_Chip(void);
uint8_t W25QXX_Wait_Busy(uint32_t timeout);
#endif









